﻿/***************************************************************************
    Copyright (c) Microsoft Corporation. All rights reserved.
    This code is licensed under the Visual Studio 
    Visualization and Modeling SDK license terms.

    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
***************************************************************************/
namespace Microsoft.VisualStudio.ArchitectureTools.CodeRepositoryQuery
{
    public partial class TypeDefinition : IMember
    {
        /// <summary>
        /// Provides a strongly typed access to the visibility of the TypeDefinition.
        /// Note that we keep <see cref="P:AccessAsShort"/> so that it can be used in entity framework queries filtering
        /// on the Access (because entity framework does not handle enums yet) such as in the following example
        /// </summary>
        /// <example>
        /// In queries we need to use the following:
        /// <code>
        ///     foreach (TypeDefinition type in context.TypeDefinitions.Where(t => t.AccessAsShort == 1 /*AccessType.Private*/))
        ///     {
        ///     }
        /// </code>
        /// whereas in code we can use
        /// <code>
        ///    if (type.Access == AccessType.Private) ...
        /// </code>
        /// </example>
        public AccessType Access
        {
            get
            {
                return (AccessType)this.AccessAsShort;
            }
            
        }

        /// <summary>
        /// Provides a strongly typed access to the Kind of the TypeDefinition
        /// Note that we keep <see cref="P:KindAsShort"/> so that it can be used in entity framework queries filtering
        /// on the type Kind (because entity framework does not handle enums yet)
        /// </summary>
        public TypeKind Kind
        {
            get
            {
                return (TypeKind)this.KindAsShort;
            }
        }

        /// <summary>
        /// Is the type static?
        /// </summary>
        bool IMember.IsStatic
        {
            get
            {
                return this.IsAbstract && this.IsSealed;
            }
        }

        #region IMember Members
        string IMember.Name
        {
            get { return this.Type.Name; }
        }

        #endregion

        /// <summary>
        /// Display label
        /// </summary>
        public override string ToString()
        {
            return this.Type.QualifiedName;
        }
    }
}
